﻿@model Cxuu.Models.EditArticleMark
@{
    ViewData["Title"] = await SystemConfig.GetByFieldNameAsync("SiteName");
    ViewData["Marks"] = await SystemConfig.GetByFieldNameAsync("Marks");
}
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>@ViewData["Title"]</title>
    <link rel="stylesheet" href="~/lib/layui/css/layui.css">
    <link rel="stylesheet" href="~/admin/css/main.css">
    <style>
        html { zoom: 100%; width: 95%; margin: 5px auto; height: auto; }
        .cxuu-content-body { font-size: 16px; line-height: 30px; height: 30px; }
            .cxuu-content-body span { width: 80px; margin-left: 10px; }
        .cxuu-mark-abho { color: black !important; font-size: 16px; }
            .cxuu-mark-abho li { line-height: 30px; }
    </style>
</head>
<body>

    <div class="layui-fluid" style="margin-bottom:50px;">
        <div class="layui-form">
            <form class="layui-form" action="" lay-filter="FormEdit">
                <div class="layui-form-item">
                    <label class="layui-form-label required">文件信息</label>
                    <div class="layui-input-block cxuu-mark-abho">

                        <ul>
                            <li>
                                <div style="color:darkblue !important;font-weight:bold;font-size:18px;" id="title"></div>
                            </li>
                            <hr>
                            <li style="color:gray;">
                                填报人：<span id="nickname"></span>
                                填报时间：<span id="InsertTime"></span>
                            </li>
                            <hr>
                            <li style="display:none;color:gray;" id="Adopt">
                                由 <span id="MarkName"></span> 于
                                <span id="GreatTime"></span> 标记为：<span class="layui-badge layui-bg-blue" id="AdoptAppraise"></span>
                            </li>
                        </ul>

                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label asp-for="AdoptAppraise" class="layui-form-label required"></label>
                        <div class="layui-input-inline">
                            <select name="AdoptAppraise" lay-verify="" lay-search="" id="marklistDom"></select>
                            <script id="markSelectTpl" type="text/html">
                                 <option value="">请选择一个标记</option>
                                {{#  layui.each(d.list, function(index, item){ }}
                                  <option value="{{ item }}">{{ item }}</option>
                                {{#  }); }}
                            </script>
                        </div>
                    </div>
                    <div class="layui-inline" id="deleteMark" style="display:none;">
                        <div class="layui-input-inline">
                            <button class="layui-btn layui-btn-danger" lay-submit lay-filter="deleteBtn" id="deleteBtn"><i class="layui-icon layui-icon-delete"></i>删除标记</button>
                        </div>
                    </div>

                </div>
                <div class="layui-form-item layui-form-text">
                    <label asp-for="Remark" class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <textarea name="Remark" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="saveBtn" id="saveBtn"><i class="layui-icon layui-icon-rate"></i>标记</button>
                    </div>
                </div>
                <input asp-for="Id" type="hidden">
                <input asp-for="Aid" type="hidden">
                <input asp-for="Uid" type="hidden">
                <input asp-for="GreatTime" type="hidden">
            </form>
        </div>
    </div>
    <script src="~/lib/jquery.min.js?v=1.12.4"></script>
    <script src="~/lib/layui/layui.js"></script>
    <script src="~/lib/cxuu-main.js"></script>
    <script>
        layui.define(function () {
            var form = layui.form, layer = layui.layer, $ = layui.jquery, element = layui.element, laytpl = layui.laytpl;

            var index = parent.layer.getFrameIndex(window.name);

            form.render();

            //渲染标记选择项
            var mark = "@ViewData["Marks"]";
            var markList = mark.split('|');
            if (markList !== null) {
                var data = {
                    "list": markList
                }
                var markListTpl = markSelectTpl.innerHTML, views = document.getElementById('marklistDom');
                laytpl(markListTpl).render(data, function (html) {
                    views.innerHTML = html;
                });
                form.render("select");
            }

            let aid = getUrlParam('aid');
            // let title = getUrlParam('title');
            // console.log("t:",title)
            $.getJSON("/Admin/ArticleMark/GetArticleMark", { "id": aid }, function (res) {
                if (res.status == 1) {
                    var data = res.data;
                    if (data != null) {
                        form.val('FormEdit', {
                            Id: data.id,
                            Aid: data.aid,
                            Uid: data.uid,
                            AdoptAppraise: data.adoptAppraise,
                            Remark: data.remark,
                            GreatTime: data.greatTime,
                        });

                        $('#title').html(data.title);
                        $('#nickname').html(data.nickname);
                        $('#InsertTime').html(data.insertTime);
                        if (data.adoptAppraise != null) {
                            $("#Adopt").show();
                            $("#deleteMark").show();
                            $('#GreatTime').html(data.greatTime);
                            $('#MarkName').html(data.markName);
                            $('#AdoptAppraise').html(data.adoptAppraise);
                        }
                    }
                } else {
                    layer.msg("数据加载失败");
                }
            });

            var dataPost = function (url, data) {
                $.post(url, data, function (res) {
                    if (res.status == 1) {
                        $("#saveBtn").hide();
                        layer.msg(res.msg, { icon: 1, time: 500 }, function () {
                            parent.layui.table.reloadData('tableReload');
                            parent.layer.close(index);
                        });
                    } else
                        layer.msg(res.msg, { icon: 2, anim: 6, time: 5000 });
                });
            }

            $('#saveBtn').click(function () {
                var field = form.val('FormEdit');
                dataPost('/Admin/ArticleMark/InsertOrUpdate', field);
                return false;
            });
            $('#deleteBtn').click(function () {
                var field = form.val('FormEdit');
                dataPost('/Admin/ArticleMark/Delete', { Id: field.Id });
                return false;
            });
        });

    </script>
</body>
</html>